//package com.chapter.sample.config.mysql;
//
//import cn.hutool.core.util.ArrayUtil;
//import com.chapter.sample.conf.EnableSampleUserDataSource;
////import com.fulu.game.config.mysql.EnableGameUserDataSource;
////import com.fulu.game.mybatis.CheckQueryLimitInterceptor;
////import com.github.pagehelper.PageHelper;
//import com.chapter.sample.mybatis.CheckQueryLimitInterceptor;
////import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageHelper;
//import io.micrometer.core.instrument.MeterRegistry;
//import jakarta.annotation.Resources;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Properties;
//
///**
// * 用户社交数据源
// */
//@Slf4j
//@Configuration
//@EnableSampleUserDataSource
//@MapperScan(basePackages = {"com.chapter.sample.dao.member"}, sqlSessionFactoryRef = "sampleUserDbSqlSessionFactory")
//public class SampleUserDbConfig {
//
//    @Bean(name = "sampleUserDbSqlSessionFactory")
//    public SqlSessionFactory sampleUserDbSqlSessionFactory(@Qualifier("sampleUserDataSource") DataSource dataSource, MeterRegistry registry) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        // 分页插件
//        PageHelper pageHelper = new PageHelper();
//        Properties properties = new Properties();
//        // false: pageNum<1和大于总页数时，返回空;true: pageNum<1返回第一页，大于总页数返回最后一页
//        properties.setProperty("reasonable", "false");
//        properties.setProperty("supportMethodsArguments", "true");
//        properties.setProperty("returnPageInfo", "check");
//        properties.setProperty("params", "count=countSql");
//        properties.setProperty("dialect", "mysql");
//        pageHelper.setProperties(properties);
//
//
//        // 添加插件，执行顺序与添加顺序相反
//        //bean.setPlugins(new Interceptor[]{new CheckQueryLimitInterceptor(registry), pageHelper});
//        bean.setPlugins(new Interceptor[]{new CheckQueryLimitInterceptor(registry)});
//
//        List<Resource> resources = new ArrayList<Resource>();
//        PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
//        resources.addAll(Arrays.asList(pathMatchingResourcePatternResolver.getResources("classpath*:mybatis/member/*.xml")));
//        //resources.addAll(Arrays.asList(pathMatchingResourcePatternResolver.getResources("classpath*:mybatis/member/**/*.xml")));
//        bean.setMapperLocations(ArrayUtil.toArray(resources, Resource.class));
//        bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
//        //mybatis-plus:
//        //  mapper-locations: classpath*:com/example/mapper/xml/*Mapper.xml
//        return bean.getObject();
//    }
//
//    @Bean(name = "sampleUserDbTransactionManager")
//    public DataSourceTransactionManager sampleUserDbTransactionManager(@Qualifier("sampleUserDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "sampleUserDbSqlSessionTemplate")
//    public SqlSessionTemplate sampleUserDbSqlSessionTemplate(@Qualifier("sampleUserDbSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}